package com.ruitu.health_2.mvp.presenter;

import com.ruitu.arad.base.BasePresenter;
import com.ruitu.arad.util.ToastUtils;
import com.ruitu.health_2.mvp.model.MallModel;
import com.ruitu.health_2.ui.mall.MallHome2Fragment;
import com.ruitu.router_module.bean.BaseResult2;
import com.ruitu.router_module.bean.PageModel2;
import com.ruitu.router_module.bean.home.AdvertContent;
import com.ruitu.router_module.bean.home.MallHomeData;
import com.ruitu.router_module.bean.product.ProHome;

import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;

public class MallPresenter {

    public static class MallHomeP extends BasePresenter<MallHome2Fragment, MallModel.MallHomeM> {
        public Disposable reqHomeData() {
            return m.reqMallHomeData().subscribe(new Consumer<BaseResult2<MallHomeData>>() {
                @Override
                public void accept(BaseResult2<MallHomeData> baseResult2) throws Exception {
                    v.hideProgress();
                    if (baseResult2.isSuccess()) {
                        v.onReqComplete(1, true, baseResult2.getData());
                    } else {
                        ToastUtils.showShortSafe(baseResult2.getMessage());
                    }
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(Throwable throwable) throws Exception {
                    v.hideProgress();
                    ToastUtils.showShortSafe("初始化商城首页失败");
                    throwable.printStackTrace();
                }
            });
        }

        public Disposable reqMallProList(String posId, int size, int num) {
            return m.reqMallProList(posId, size, num).subscribe(new Consumer<BaseResult2<PageModel2<AdvertContent<ProHome>>>>() {
                @Override
                public void accept(BaseResult2<PageModel2<AdvertContent<ProHome>>> pageResult) throws Exception {
                    v.hideProgress();
                    if (pageResult.isSuccess()) {
                        v.onReqComplete(2, true, pageResult.getData());
                    } else {
                        ToastUtils.showShort(pageResult.getMessage());
                    }
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(Throwable throwable) throws Exception {
                    v.hideProgress();
                    throwable.printStackTrace();
                }
            });
        }
    }
}
